package dao.impl;

import bean.Notice;
import bean.Order;
import dao.BaseDao;
import dao.OrderDao;

import java.util.ArrayList;

public class OrderDaoImpl extends BaseDao implements OrderDao {

    @Override
    public int insert(Order order) {
        String sql = "INSERT INTO `t_order` (`money`,`receiverAddress`,`receiverName`,`receiverPhone`,`paystate`,`ordertime`,`user_id`)VALUES(?,?,?,?,?,?,?)";
        return update(sql,order.getMoney(),order.getReceiverAddress(),order.getReceiverName(),order.getReceiverPhone(),
                order.getPaystate(),order.getOrdertime(),order.getUser_id());
    }

    @Override
    public int delete(Integer id) {
        String sql = "DELETE FROM `t_order` WHERE `id`=?";
        return update(sql,id);
    }

    @Override
    public int update(Order order) {
        String sql = "UPDATE `t_order` SET `money`=?,`receiverAddress`=?,`receiverName`=?,`receiverPhone`=?,`paystate`=?,`ordertime`=?,`user_id`=? WHERE `id`=?";
        return update(sql,order.getMoney(),order.getReceiverAddress(),order.getReceiverName(),order.getReceiverPhone(),
                order.getPaystate(),order.getOrdertime(),order.getUser_id(),order.getId());
    }

    @Override
    public Order queryById(Integer id) {
        String sql = "SELECT * FROM `t_order` WHERE `id`=?";
        return queryForOne(Order.class,sql,id);
    }

    @Override
    public ArrayList<Order> queryAll() {
        String sql = "SELECT * FROM `t_order`";
        return queryForList(Order.class,sql);
    }
}
